package com.lottery.shadowbd.ui.activity;

import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.lottery.shadowbd.R;
import com.lottery.shadowbd.utils.SharedPreUtil;

import static com.lottery.shadowbd.support.Constant.isFirst;

/**
 * 欢迎页
 * 2018/03/03
 */
public class SplashActivity extends AppCompatActivity {

    private static final int FLAG_NEXT = 0x01;

    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);

            Intent mIntent = new Intent();

            if("1".equals(SharedPreUtil.getInstance(SplashActivity.this).getString(isFirst,"0"))) {
                mIntent.setClass(SplashActivity.this,HomeActivity.class);
            } else {
                mIntent.setClass(SplashActivity.this,GuideActivity.class);
            }

            startActivity(mIntent);
            finish();
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        mHandler.sendEmptyMessageDelayed(FLAG_NEXT,3000);
    }

    @Override
    protected void onDestroy() {
        if(mHandler != null) {
            mHandler.removeCallbacksAndMessages(null);
            mHandler = null;
        }

        super.onDestroy();
    }
}
